<!--1 脚本  -->
<script setup lang="ts" name="Login">
const router = useRouter()

import { login } from '@/api/system/login/index'

//变量
const form = reactive({
  username: '',
  password: '',
})

/**
 * 登录接口
 */
async function toLogin() {
  // 登录 获取token
  const { code, data: token } = await login(form)

  // console.log('token',token);
  if (code === 200) {
    //存储token
    sessionStorage.setItem('token', token)
    //alert('登录成功')
    // 获取用户身份、获取权限
    router.push('/')
  }
}
</script>

<!-- 2 模板 -->
<template>
  <div class="containerLogin">
    <div class="form">
      <h3>xxxxxxx管理系统1</h3>
      <el-form :model="form" label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="form.password" autocomplete="off"></el-input>
        </el-form-item>

        <div>
          <el-button style="width: 90%" type="primary" @click="toLogin">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<!-- 3 样式 -->
<style scoped>
.containerLogin {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;

  .form {
    width: 400px;
    height: 300px;
    border: solid 1px skyblue;
    border-radius: 10px;
    box-shadow: 0 0 30px skyblue;
    padding: 30px;

    .form > h3 {
      width: 100%;
      text-align: center;
    }
  }
}
</style>
